package familytree.yu.com.sso.model;

import familytree.yu.com.sso.enums.ErrorCodeEnum;
import lombok.Data;

/**
 * @Author: yuyunbo
 * @Date: 2021/2/23 20:55
 * @Description:
 */
@Data
public class ResultVo<T> {
    private int code;
    private String message;
    private T data;

    public void succeed() {
        code = 0;
        message = "succeed";
    }

    public static <T> ResultVo<T> succeed(T body) {
        ResultVo<T> restRes = new ResultVo<>();
        restRes.succeed();
        restRes.setData(body);
        return restRes;
    }


    public static ResultVo failed(int code, String message) {
        ResultVo restRes = new ResultVo();
        restRes.setCode(code);
        restRes.setMessage(message);
        return restRes;
    }

    public static ResultVo failed(ErrorCodeEnum errorEnum) {
        ResultVo restRes = new ResultVo();
        restRes.setCode(errorEnum.code());
        restRes.setMessage(errorEnum.msg());
        return restRes;
    }

}
